<!DOCTYPE html>
<html>
<head>
    <title>Energy Band Diagram</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="physicsCanvas" width="600" height="500"></canvas>
    <script>
        const canvas = document.getElementById('physicsCanvas');
        const ctx = canvas.getContext('2d');

        /**
         * Draws a vertical curly brace.
         * @param {CanvasRenderingContext2D} ctx - The rendering context.
         * @param {number} x - The x-coordinate of the brace's spine.
         * @param {number} y1 - The starting y-coordinate.
         * @param {number} y2 - The ending y-coordinate.
         * @param {number} width - The horizontal width of the brace from spine to tip.
         * @param {number} sharpness - Controls the curvature at the ends.
         */
        function drawVerticalBrace(ctx, x, y1, y2, width, sharpness) {
            const yMid = (y1 + y2) / 2;
            const xTip = x - width;

            ctx.beginPath();
            ctx.moveTo(x, y1);
            // Top half
            ctx.bezierCurveTo(x, y1 + sharpness, xTip, yMid - sharpness, xTip, yMid);
            // Bottom half
            ctx.bezierCurveTo(xTip, yMid + sharpness, x, y2 - sharpness, x, y2);
            ctx.stroke();
        }

        // --- Drawing Parameters ---
        const bandX = 50;
        const bandWidth = 300;
        const bandHeight = 80;

        const conductionY = 70;
        const valenceY = 270;
        const forbiddenGap = valenceY - (conductionY + bandHeight);

        const braceX = 420;
        const braceWidth = 20;

        const textX = 450;
        const textStyle = '24px sans-serif';
        const textColor = 'black';
        const lineHeight = 28;

        // --- Draw Bands ---
        ctx.lineWidth = 2;
        ctx.strokeStyle = 'black';

        // Conduction Band
        const gradientConduction = ctx.createLinearGradient(0, conductionY, 0, conductionY + bandHeight);
        gradientConduction.addColorStop(0, '#f0f0f0'); // Lighter top
        gradientConduction.addColorStop(1, '#d3d3d3'); // Darker bottom
        ctx.fillStyle = gradientConduction;
        ctx.fillRect(bandX, conductionY, bandWidth, bandHeight);
        ctx.beginPath();
        ctx.moveTo(bandX, conductionY);
        ctx.lineTo(bandX + bandWidth, conductionY);
        ctx.moveTo(bandX, conductionY + bandHeight);
        ctx.lineTo(bandX + bandWidth, conductionY + bandHeight);
        ctx.stroke();

        // Valence Band
        const gradientValence = ctx.createLinearGradient(0, valenceY, 0, valenceY + bandHeight);
        gradientValence.addColorStop(0, '#f0f0f0'); // Lighter top
        gradientValence.addColorStop(1, '#d3d3d3'); // Darker bottom
        ctx.fillStyle = gradientValence;
        ctx.fillRect(bandX, valenceY, bandWidth, bandHeight);
        ctx.beginPath();
        ctx.moveTo(bandX, valenceY);
        ctx.lineTo(bandX + bandWidth, valenceY);
        ctx.moveTo(bandX, valenceY + bandHeight);
        ctx.lineTo(bandX + bandWidth, valenceY + bandHeight);
        ctx.stroke();


        // --- Draw Braces and Labels ---
        ctx.lineWidth = 1.5;
        ctx.fillStyle = textColor;
        ctx.font = textStyle;
        ctx.textAlign = 'left';

        // Conduction Band Label
        let y_mid_conduction = conductionY + bandHeight / 2;
        let sharpness_conduction = (bandHeight / 2) * 0.5;
        drawVerticalBrace(ctx, braceX, conductionY, conductionY + bandHeight, braceWidth, sharpness_conduction);
        ctx.fillText('conduction', textX, y_mid_conduction - lineHeight / 2 + 5);
        ctx.fillText('band', textX, y_mid_conduction + lineHeight / 2 + 5);

        // Forbidden Band Label
        let y_mid_forbidden = (conductionY + bandHeight) + forbiddenGap / 2;
        let sharpness_forbidden = (forbiddenGap / 2) * 0.5;
        drawVerticalBrace(ctx, braceX, conductionY + bandHeight, valenceY, braceWidth, sharpness_forbidden);
        ctx.fillText('forbidden', textX, y_mid_forbidden - lineHeight / 2 + 5);
        ctx.fillText('band', textX, y_mid_forbidden + lineHeight / 2 + 5);
        
        // Valence Band Label
        let y_mid_valence = valenceY + bandHeight / 2;
        let sharpness_valence = (bandHeight / 2) * 0.5;
        drawVerticalBrace(ctx, braceX, valenceY, valenceY + bandHeight, braceWidth, sharpness_valence);
        ctx.fillText('valence', textX, y_mid_valence - lineHeight / 2 + 5);
        ctx.fillText('band', textX, y_mid_valence + lineHeight / 2 + 5);
        
        // --- Draw Caption ---
        ctx.font = 'bold 24px sans-serif';
        ctx.textAlign = 'center';
        const captionX = bandX + bandWidth / 2;
        const captionY = 450;
        ctx.fillText('Fig. 10.1', captionX, captionY);
        
    </script>
</body>
</html>